//
//  XSAVPlayerViewController.m
//  AudioVideo
//
//  Created by xueshan1 on 2019/10/25.
//  Copyright © 2019 xueshan1. All rights reserved.
//

#import "XSAVPlayerViewController.h"

@interface XSAVPlayerViewController ()
@property (weak, nonatomic) IBOutlet UIButton *backBtn;

@end

@implementation XSAVPlayerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor blackColor];
    
    if (self.photoModel) {
        
        [XSPhotosManager requestVideoPlayItem_ForAsset:self.photoModel.asset progressHandler:^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
            
        } completion:^(AVPlayerItem * _Nullable playerItem, NSDictionary *info) {
           
            [[XSAVPlayer shareInstance]playVideoWithPlayItem:playerItem onPlayView:self.view belowView:self.backBtn];
            
        }];
        
    }else if (self.videoURL ) {
        //在videDidLoad 调用,有时候,刚录制的视频,获取不到
        [[XSAVPlayer shareInstance]playVideoWithURLString:self.videoURL.absoluteString onPlayView:self.view belowView:self.backBtn isLocalFile:YES];
        
    }
    
}

- (IBAction)backBtnAction:(id)sender {
    [[XSAVPlayer shareInstance] sf_deallocPlayer];
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}


@end
